package com.weds.data_sync.controller;

import com.weds.data_sync.pojo.dto.LoginDto;
import com.weds.data_sync.service.AccountService;
import com.weds.data_sync.util.CommonUtil;
import com.weds.data_sync.util.JsonData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 数据同步账户表 前端控制器
 * </p>
 *
 * @author lhw
 * @since 2023-12-29
 */
@Slf4j

@Tag(name = "账户接口")
@RestController
@RequestMapping("/api/account/v1")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Operation(summary = "获取图片验证码")
    @GetMapping("verify_code")
    public void getVerifyCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        CommonUtil.getImageCaptcha(request, response, redisTemplate);
    }

    @Operation(summary = "登录接口")
    @PostMapping("login")
    public JsonData login(@RequestBody @Validated LoginDto loginDto, HttpServletRequest request) {
        return accountService.login(loginDto, request);
    }

}
